﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace RazorTemplateEngine
{
    public class TemplateDriver
    {
        private static Type defaultTemplateBaseType = typeof(__TemplatePage);

        public static object Drive(ActionResult actionResult)
        {
            AssemblyContext context = new AssemblyContext();
            AssemblyReferenceResolver assemblyResolver = new AssemblyReferenceResolver(Assembly.GetCallingAssembly());
            List<Assembly> referenceAssemblies = assemblyResolver.RecurseReferenceAssemblies;
            referenceAssemblies.Add(Assembly.GetCallingAssembly());
            context.ReferenceAssemblies = referenceAssemblies.ToArray();
            return actionResult.Execute(context);
        }

        public static Type DefaultTemplateBaseType
        {
            get { return defaultTemplateBaseType; }
            set { defaultTemplateBaseType = value; }
        }
    }
}
